/**
 * Created by Administrator on 2018/5/10.
 */
const mongoose = require('mongoose')
mongoose.Promise=global.Promise;
const DB_URL='mongodb://localhost/job'
mongoose.connect(DB_URL)
// mongoose.connection.on('connected',function(){
//     console.log('mongo connect success')
// })
var db = mongoose.connection;
db.on('error', function (error) {
  console.log('数据库连接失败：' + error);
});
db.on('open', function () {
  console.log('——数据库连接成功！——');
});
const models = {
  user:{
    'user':{type:String,reqire:true},
    'pwd':{type:String,reqire:true},
    'type':{type:String,reqire:true},
    'avatar':{type:String},
    'desc':{type:String},
    'title':{type:String},
    'company':{type:String},
    'money':{type:String},
  },
  chat:{}
}

for (let m in models){
  mongoose.model(m, new mongoose.Schema(models[m]))
}

module.exports = {
  getModel:function(name){
    return mongoose.model(name)
  }
}